To display multiple plots on the same page NCL provides the gsn_panel function to do this for you. The name of the plots and its appearance likely in a table in rows and colums have to be given. With the panel resources you can set a panel title and use a common labelbar. </br></br>
Notes:
Open file and read the variables t and rhum. The data set is included in the NCL package.
In [1]:
f = addfile("$NCARG_ROOT/lib/ncarg/data/nug/rectilinear_grid_3D.nc","r")
temp = f->t
rhum = f->rhumidity
Send graphic output to PNG files plot_panel_plots.000001.png, plot_panel_plots.000002.png, ...
In [2]:
wks_type = "png"
wks_type@wkWidth = 500
wks_type@wkHeight = 500
wks = gsn_open_wks(wks_type,"plot_panel_plots")
Define the plot resources for temp and rhum. Use contour fill and different color maps. </br></br> Note: Set gsnDraw and gsnFrame to False because gsn_panel will do that for you.
In [3]:
rest = True
rest@gsnDraw = False ;-- create the plots in memory
rest@gsnFrame = False ;-- don't advance the frame
rest@cnFillOn = True
resr = rest
rest@cnFillPalette = "cmp_b2r"
rest@gsnCenterString = "lev=100000 Pa"
resr@cnFillPalette = "MPL_YlGnBu"
resr@gsnCenterString = "lev=100000 Pa"
Create the plots of lev=100000 Pa in memory.
In [4]:
plot_temp_lev1 = gsn_csm_contour_map(wks,temp(0,0,:,:),rest)
plot_rhum_lev1 = gsn_csm_contour_map(wks,rhum(0,0,:,:),resr)
Set panel title and create a panel with 2 rows and 1 column.
In [5]:
pres = True
pres@gsnPanelMainString = "Panel 2 rows x 1 column (/2,1/)"
gsn_panel(wks,(/plot_temp_lev1,plot_rhum_lev1/),(/2,1/),pres)
Create a panel with 1 rows and 2 column. There is a lot of white space around the plot and if you want to crop it see ImageMagick's convert program.
In [6]:
pres@gsnPanelMainString = "Panel 1 rows x 2 column (/1,2/)"
gsn_panel(wks,(/plot_temp_lev1,plot_rhum_lev1/),(/1,2/),pres)
Create additional plots (lev=100000,1000 Pa) and create a panel with 2 rows and 2 column.
In [7]:
rest@gsnCenterString = "lev=1000 Pa"
plot_temp_lev16 = gsn_csm_contour_map(wks,temp(0,16,:,:),rest)
resr@gsnCenterString = "lev=1000 Pa"
plot_rhum_lev16 = gsn_csm_contour_map(wks,rhum(0,16,:,:),resr)
pres@gsnPanelMainString = "Panel 2 rows x 2 column (/2,2/)"
gsn_panel(wks,(/plot_temp_lev1,plot_rhum_lev1,plot_temp_lev16,plot_rhum_lev16/),(/2,2/),pres)
Create additional plots (lev=25000 Pa).
In [8]:
rest@gsnCenterString = "lev=25000 Pa"
plot_temp_lev3 = gsn_csm_contour_map(wks,temp(0,3,:,:),rest)
resr@gsnCenterString = "lev=25000 Pa"
plot_rhum_lev3 = gsn_csm_contour_map(wks,rhum(0,3,:,:),resr)
Create the panel of 3 rows and 2 column with all plots. For a better readability put the plot names into an Array.
In [9]:
plots = (/plot_temp_lev1,plot_rhum_lev1, \
plot_temp_lev3,plot_rhum_lev3, \
plot_temp_lev16,plot_rhum_lev16/)
pres@gsnPanelMainString = "Panel 2 rows x 2 column (/3,2/)"
gsn_panel(wks,plots,(/3,2/),pres)